package com.xm.servlet;

import com.xm.biz.CartBiz;
import com.xm.biz.GoodsBiz;
import com.xm.biz.UserAddressBiz;
import com.xm.biz.impl.CartBizImpl;
import com.xm.biz.impl.GoodsBizImpl;
import com.xm.biz.impl.UserAddressBizImpl;
import com.xm.po.Cart;
import com.xm.po.Goods;
import com.xm.po.UserAddress;
import com.xm.po.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author xie'lin'feng
 * @date 2020-08-21-20:38
 * @description 支付详情页面
 */
@WebServlet("/payCart")
public class PayInfoServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Users user = (Users) session.getAttribute("user");
        CartBiz cartBiz = new CartBizImpl();
        GoodsBiz goodsBiz = new GoodsBizImpl();
        UserAddressBiz addressBiz = new UserAddressBizImpl();
        //获取用户购物车选中的信息
        List<Cart> payList = cartBiz.getCartByIdChecked(user.getUserId());
        //获取用户地址
        List<UserAddress> userAddress = addressBiz.getUserAddress(user.getUserId());
        //获取用户默认地址
        UserAddress isDefault = addressBiz.getIsDefault(user.getUserId());
        session.setAttribute("isDefault",isDefault);
        session.setAttribute("userAddress",userAddress);
        session.setAttribute("payList",payList);
        resp.sendRedirect("pay.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
